import { cardBaseScriptAction, showCardScriptActionDlg, isShowScriptActionDlg } from '../../utils/baseScriptUtil'
import { showWarningDialog } from '../../../../../scmpub/scmpub/pub/tool/messageUtil'
import { AREA, URL, FIELDS, FSTATUSFLAG } from '../../constance'
import { getLangByResId } from '../../../../../scmpub/scmpub/pub/tool/multiLangUtil'

export default function (props, skipCodes, saveCallback, assign) {
	let sendCount = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.sendemailcount).value //累计发送邮箱次数
	// let supplierUser = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.supplieruser).value;
	// if(supplierUser==null){
	// 	showWarningDialog(getLangByResId(this, '警告'), getLangByResId(this, '供应商用户不能为空'))
	// 	return;
	// }	
	let businessemail = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.businessemail).value
	if (businessemail == null) {
		showWarningDialog(getLangByResId(this, '警告'), getLangByResId(this, '业务邮箱不能为空'))
		return
	}

	let msg = ''
	if (!sendCount || sendCount < 1) {
		msg = '确认发送？'
	} else {
		msg = '是否再次发送？'
	}
	showWarningDialog(getLangByResId(this, '确认发送'), getLangByResId(this, msg), {

		beSureBtnClick: () => {
			let fstatusflag = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.fstatusflag).value // 合同状态
			let visible = fstatusflag == FSTATUSFLAG.validate
			if (visible) {
				//发送邮件
				cardBaseScriptAction.call(
					this,
					props,
					'/nccloud/ct/purdaily/sendMail.do',
					getLangByResId(this, '发送邮件成功'),
					null,
					assign,
					skipCodes,
					saveCallback
				)
				// ajax({
				// 	url: '/nccloud/ct/purdaily/sendMail.do',
				// 	data: props,
				// 	success: res => {							
				// 		showWarningDialog('是否成功','发送邮件成功');
				// 	},
				// 	error: res => {

				// 	},
				// });		
			} else {
				//非生效状态
				showWarningDialog('是否成功', '发送邮件失败，合同未生效')
			}
		}
	})
}